<template>
	<view class="page" @touchstart="touchStart" @touchend="touchEnd">
		<view >
			<u-navbar title-color="#fff" back-icon-color="#ffffff"
				:is-fixed="isFixed" :is-back="isBack" 
				:background="background" 
				:back-text-style="{color: '#fff'}" :title="title1" 
				:back-icon-name="backIconName" :back-text="backText"
				:border-bottom="true" @click="back">
			</u-navbar>
			
		</view>
		<form>
			<view class="uni-textarea">
				<!-- <u-form-item label="学号" label-width="140" prop="stuNumber">
					
					<u-input v-model="user.stuNumber" placeholder="输入一下学号吧!" type="text" ></u-input>
					<u-icon name="integral-fill" color="#2979ff" size="35" @click="getall"></u-icon>
				</u-form-item> -->
				<textarea placeholder="这一刻的想法..." v-model="newcomment.content" />
			</view>
			<!-- <view class="uni-list list-pd">
				<view class="uni-list-cell cell-pd">
					<view class="uni-uploader">
						<view class="uni-uploader-head">
							<view class="uni-uploader-title"></view>
							<view class="uni-uploader-info">{{imageList.length}}/9</view>
						</view>
						<view class="uni-uploader-body">
							<view class="uni-uploader__files">
								<block v-for="(image,index) in imageList" :key="index">
									<view class="uni-uploader__file" style="position: relative;">
										<image class="uni-uploader__img" mode="aspectFill" :src="image" :data-src="image" @tap="previewImage"></image>
										<view class="close-view" @click="close(index)">×</view>
									</view>
								</block>
								<view class="uni-uploader__input-box" v-show="imageList.length < 9">
									<view class="uni-uploader__input" @tap="chooseImage"></view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view> -->
			
			<view class="footer">
				<button type="default" class="feedback-submit" @click="publish">提交</button>
			</view>
		</form>
	</view>
</template>

<script>
	// import image from '@/common/image.js';
	
	var sourceType = [
		['camera'],
		['album'],
		['camera', 'album']
	]
	var sizeType = [
		['compressed'],
		['original'],
		['compressed', 'original']
	]
	export default {
		data() {
			return {
				//顶部导航栏
				// 顶部导航栏
				title1: '评论',
				collected:false,
				backText: '返回',
				backIconName: 'nav-back',
				right: false,
				showAction: false,
				rightSlot: false,
				useSlot: false,
				background: {
					'background-image': 'linear-gradient(45deg, #2BC3C8, #84E7B9)'
				},
				isBack: true,
				search: false,
				custom: true,
				isFixed: true,
				keyword: '',
				
				// title: 'choose/previewImage',
				// title: 'choose/previewImage',
				
				imageList: [],
				
				
				
				sourceTypeIndex: 2,
				sourceType: ['拍照', '相册', '拍照或相册'],
				sizeTypeIndex: 2,
				sizeType: ['压缩', '原图', '压缩或原图'],
				countIndex: 8,
				count: [1, 2, 3, 4, 5, 6, 7, 8, 9],
				
				//侧滑返回start
				startX: 0, //点击屏幕起始位置
				movedX: 0, //横向移动的距离
				endX: 0, //接触屏幕后移开时的位置
				//end
				parsedIndex: 0,
				userid:'',
				user:{
					id:'',
					name:'',
					stuNumber:'',
					pwd:'',
					age:'',
					gender:'',
					address:'',
					tel:'',
					idNumber:'',
					hobby:'',
					nationality:'', 
					politicalStatus:'',
					college: '',
					major:'',
					dormitory:'',
					motto: '',
				},
				forum:{
					id:'',
					stuNumber:'',
					note:'',
					like:''
				},
				newcomment:{
					forumId:'',
					stuNumber:'',
					content:''
				}
			}
		},
		onLoad(options) {
		    console.log(options.index);
		    // 现在你可以在目标页面中使用 index 进行操作
		     this.parsedIndex = parseInt(options.index)+1;
		 const value5=uni.getStorageSync('user1')
		 console.log(value5)
		 
		 this.user.stuNumber=value5.stuNumber
		 console.log(this.user)
		},
	
		methods: {
			back() {
				uni.navigateBack();
			},
			getall(){
				// console.log(7)
				console.log(1)
			    console.log(this.user)
			    console.log(2)
			
			},
			
			async publish(){
				// console.log("565")
				// console.log(this.parsedIndex)
				
				
				this.newcomment.forumId = this.parsedIndex;
				// console.log(this.newcomment.forumId)
				
				if (!this.newcomment.content) {
					uni.showModal({ content: '内容不能为空', showCancel: false, });
					return;
				}
				uni.request({
					url:'http://192.168.137.139:8080/getAllInfo',
					method: "POST",
					data:this.user,
					success:(res)=> {
						
						if(res.data.code*1==200){
							//console.log(res.data.result);
							//this.$u.toast('登录成功');
							
						  // console.log(3)
						  // console.log(res)
						  // console.log(4)
						uni.setStorageSync('user',res.data.result);
						this.user=uni.getStorageSync('user');
						this.userid=this.user.stuNumber;
						// console.log(this.newcomment.stuNumber)
						 this.newcomment.stuNumber=this.userid;
						 // 延时 100 毫秒执行
						 setTimeout(() => {
						           this.uni.request();
						         }, 1000);
						 // console.log(5)
							uni.request({
								url:'http://192.168.137.139:8080/newComment',
								data:this.newcomment,
								method: "POST",
								success:(res)=> {
									
									if(res.data.code*1==200){
										console.log(this.newcomment)
										console.log(res);
										// console.log("978");
										//this.$u.toast('登录成功');
								
									
									
									 // console.log(5)
										uni.hideLoading();
										uni.showToast({
											icon:'success',
											title:"发布成功"
										})
										uni.navigateBack()
									// uni.navigateTo({
									// 	url:"/pages/luntan/index"
									// })
									}
									else{
										this.$u.toast('发表失败!');
										
									}
								}
							})
							
						}
						else{
							this.$u.toast('学号不存在');
							
						}
					}
				  });
				uni.showLoading({title:'发布中'});
				console.log(this.newcomment)
				 
		// 		uni.request({
		// 			url:'http://192.168.137.139:8080/newComment',
		// 			data:this.newcomment,
		// 			method: "POST",
		// 			success:(res)=> {
						
		// 				if(res.data.code*1==200){
		// 					console.log(this.newcomment)
		// 					console.log(res);
		// 					// console.log("978");
		// 					//this.$u.toast('登录成功');
					
						
		
		// 				 // console.log(5)
		// 					uni.hideLoading();
		// 					uni.showToast({
		// 						icon:'success',
		// 						title:"发布成功"
		// 					})
		// 				// uni.navigateTo({
		// 				// 	url:"/pages/luntan/index"
		// 				// })
		// 				}
		// 				else{
		// 					this.$u.toast('发表失败!');
							
		// 				}
		// 			}
		// 		})
				
			},
			
			
			
			touchStart: function(e) {
				this.startX = e.mp.changedTouches[0].pageX;
			},
			
			touchEnd: function(e) {
				this.endX = e.mp.changedTouches[0].pageX;
				if (this.endX - this.startX > 200) {
					uni.navigateBack();
				}
			}
		}
	}
</script>

<style scoped>
	
	.footer {
		margin-top: 80upx;
	}
	
	.cell-pd {
		padding: 20upx 30upx;
	}

	.uni-textarea {
		width: auto;
		padding: 20upx 25upx;
		line-height: 1.6;
		height: 300upx;
	}
	.uni-list::before {
		height: 0;
	}
	.uni-list:after {
		height: 0;
	}
	.list-pd {
		margin-top: 0;
	}
	.close-view{
	    text-align: center;
		line-height:30upx;
		height: 35upx;
		width: 35upx;
		background: #ef5350;
		color: #FFFFFF;
		position: absolute;
		top: 1upx;
		right: 1upx;
		font-size: 35upx;
		border-radius: 8upx;
	}
	.page {
		width: 750upx;
		height: 100%;
	}
</style>
